<template>
    <h2>投资项目添加</h2>
    <table class="table table-border" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td>投资项目名称</td>
            <td><input type="text" v-model="info.name"></td>
        </tr>
        <tr>
            <td>投资总金额</td>
            <td><input type="text" v-model="info.smoney"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="发布" @click="add"></td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import axios from 'axios'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()

const info=ref({
    name:"",
    smoney:""
})

const add=()=>{
    if(info.value.name==""){
        alert('投资项目名称不能为空')
        return
    }
    if(isNaN(Number(info.value.smoney))){
        alert('投资总金额必须为数字')
        return
    }
    axios({
        url:"https://localhost:44394/api/InverstController/InverstADD",
        data:{
            IName:info.value.name,
            IMoney:info.value.smoney
        },
        method:"post"
    })
    .then(res=>{
        if(res.data==-1){
            alert('投资项目名称已存在')
            return
        }
        if(res.data>0){
            alert('投资项目添加成功')
            router.push("/ginverstshow")
        }else{
           alert('投资项目添加失败')
        }
    })
}
</script>